package com.qm.console.utils;

import com.qm.console.pubdef.dto.user.PageInfoDTO;

import java.util.List;

public class PageUtils {
    public static PageInfoDTO structurePageInfo(List list, Integer total, Integer count, Integer page, Integer limit){
        PageInfoDTO pageInfo = new PageInfoDTO();
        pageInfo.setList(list);
        pageInfo.setTotal(total);
        pageInfo.setSize(count);
        pageInfo.setEndRow((page - 1) * limit+count);
        pageInfo.setHasNextPage(count>pageInfo.getEndRow()?true:false);
        pageInfo.setHasPreviousPage(page != 1);
        pageInfo.setIsFirstPage(page == 1);
        pageInfo.setIsLastPage(count>pageInfo.getEndRow()?false:true);
        Integer mor = total>limit?total/limit:0;
        Integer rem = total>limit?total % limit:0;
        pageInfo.setLastPage(rem==0?mor:mor+1);
        pageInfo.setNavigateLastPage(rem==0?mor:mor+1);
        pageInfo.setNextPage(pageInfo.getHasNextPage()?page+1: 0);
        pageInfo.setPageNum(rem==0?mor:mor+1);
        pageInfo.setPageSize(limit);
        pageInfo.setPages(rem==0?mor:mor+1);
        pageInfo.setPrePage(page-1);
        pageInfo.setStartRow((page - 1) * limit+1);
        pageInfo.setStatus(1);  // 用来判断是 已审核数据 还是 未审核数据
        return pageInfo;
    }
}
